﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MainWindow.aspx.cs" Inherits="Management.MainWindow" %>
<%@ Import Namespace="Management" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Personal Organizer 2015</title>
    <link rel="stylesheet" type="text/css" href="/Resources/css/main.css"/>
    <link rel="stylesheet" type="text/css" href="/Resources/css/default.css"/>
    <script type="text/javascript" src="/Resources/js/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="/Resources/js/default.js"></script>
    <script type="text/javascript" src="/Resources/js/main.js"></script>
</head>
<body>
    <form id="form1" runat="server">
        <asp:HiddenField runat="server" ID="__EVENTTARGET"/>
        <asp:HiddenField runat="server" ID="__EVENTARGUMENT"/>
        <h1 style="text-align: center; margin: auto; font-family: Curlz MT;">ПЕРСОНАЛЬНЫЙ ОРГАНАЙЗЕР 2015. ГЛАВНАЯ</h1>
        <div id="addWeekMainBtn">Добавить неделю</div>
        <div id="btn_left"></div>
        <div id="btn_right"></div>
        <div id="content">
        <table border="1" style="float: left;">
            <tr>
                <td id="goalHead">Цели<div id="addGoal" title="Добавить новую цель"></div></td>
                <td id="taskHead">Задачи</td>
            </tr>
            <tr>
                <td style="height: 18px;" colspan = "2"></td>
            </tr>
            <% var goals = dao.GetAllGoals();
               var i = 1;
               foreach (var goal in goals)
               {%>
                   <tr>
                       <td class="goalName"><span><%= goal.Name%></span>
                           <div class="dropDownGoal" id="<%="dropDownGoal" + i%>" title="Меню цели">
                               <div id="<%="dropDownGoalVal" + i%>" class="dropDownGoalVal" style="display: none">
                                   <div onclick="addNewTask('<%=goal.Name%>')" class="newTaskDiv">Новая задача</div>
                                   <button class="delGoal" onclick="__doPostBack('removeGoal','<%=goal.Name %>')">Удалить цель</button>
                               </div>
                           </div>
                       </td>
                        <td>
                            <% var tasks = dao.GetAllTasks(goal.Id);
                                foreach (var task in tasks)
                                {%>
                                 <div class="task">
                                     <div class="taskName" onclick="showDescription('<%=dao.GetTaskDescription(goal.Id, task)%>', '<%=task.name %>~<%=goal.Name %>', '<%=task.status %>');"><%=task.name %></div>
                                     <button class="removeTask" onclick="__doPostBack('removeTask', '<%=goal.Name %>~<%=task.name %>')" title="Удалить задачу"></button>
                                 </div>
                                <%} %>
                        </td>
                    </tr>
               <% i++;
               } %>
        </table>
        
        <% var weeks = dao.GetLastWeek();%>
            <script type="text/javascript">
                var weeks = <%=weeks%>;
            </script>
            <%for (i = 1; i <= weeks; i++)
           {%>
               <table border="1" style="float: left" id="table_<%=i %>">
                   <tr>
                       <td style="text-align: center; min-width: 120px;"><a class="WeekBtn" href="/DetailedView.aspx?goals=all&tasks=all&week=<%=i %>">Неделя <%=i %></a></td>
                   </tr>
                   <tr>
                       <td style="text-align: center; min-width: 120px;"><%=dao.GetMinWeekDate(i)%> - <%=dao.GetMaxWeekDate(i)%></td>
                   </tr>
                   <% foreach (var goal in goals)
                      {%>
                          <tr><td style="text-align: center">
                                 <% var tasks = dao.GetAllTasks(goal.Id);
                                    if (tasks.Count == 0)
                                    {%>
                                        <div style="height: 25px;"></div>
                                    <%}
                                    else
                                    {
                                        foreach (var task in tasks)
                                        {
                                            var contains = false;
                                            foreach (var week in dao.GetWeekDataByNumberAndTask(i, task))
                                            {
                                                if (week.time != null)
                                                {
                                                    if (week.Task1.status == "In progress")
                                                    { %>
                                                        <div class="inProgressTask" onclick="redirectToDeetailedView('/DetailedView.aspx?goals=1&tasks=1&goal=<%=goal.Id%>&task=<%=task.Id %>&week=<%=i %>')"></div>
                                                 <% }
                                                    else
                                                    { %>
                                                        <div class="readyTask" onclick="redirectToDeetailedView('/DetailedView.aspx?goals=1&tasks=1&goal=<%=goal.Id%>&task=<%=task.Id %>&week=<%=i %>')"></div>
                                                 <% }
                                                    contains = true;
                                                    break;
                                                }
                                            }
                                            if (!contains)
                                            { %>
                                                <div style="height: 25px;"></div>
                                         <% }
                                        }
                                    } %>
                          </td></tr>
                    <%} %>
               </table>
         <%} %>
        
        </div>    

        <div id="overlay"></div>

        <div class="smallPop" id="goalPop">
            <div class="closeGoalPop"></div>
            <div class="popHeader">Добавить Новую Цель</div>
            <div class="headerSeparator"></div>
            <div id="goalAddTxt">Введите имя новой цели:</div>
            <asp:TextBox runat="server" ID="newGoalName"/>
            <asp:Button runat="server" ID="addGoalBtn" Text="Добавить" OnClientClick="return validateGoal();" OnClick="addGoalBtn_OnClick"/>
        </div>

        <div class="smallPop" id="addWeekPop">
            <div class="closeWeekPop"></div>
            <div class="popHeader">Добавить Неделю</div>
            <div class="headerSeparator"></div>
            <div id="weekAddTxt" class="taskTxt">Введите номер недели:</div>
            <asp:TextBox ID="weekAmount" runat="server" />
            <asp:Button ID="addWeekBtn" runat="server" Text="Добавить" OnClientClick="return validateWeek();" OnClick="addWeekBtn_OnClick" />
        </div>

        <div id="addTaskPopUp">
            <div id="closeTaskPop"></div>
            <div class="popHeader">Добавить Новую Задачу</div>
            <div class="headerSeparator"></div>
            <div id="goalNameTxt" class="taskTxt">Имя цели:</div>
            <div id="taskNameTxt" class="taskTxt">Название новой задачи:</div>
            <div id="taskDescriptionTxt" class="taskTxt">Описание новой задачи:</div>
            <asp:TextBox runat="server" ID="goalNameTask"/>
            <asp:TextBox runat="server" ID="newTaskName"/>
            <asp:TextBox runat="server" ID="newTAskDescription" TextMode="multiline" Columns="50" Rows="5"/>
            <asp:Button runat="server" ID="addTaskBtn" Text="Добавить" OnClientClick="return validateTask();" OnClick="addTaskBtn_OnClick"/>
        </div>
        
        <div class="smallPop" id="descriptionPop">
            <div class="closeGoalPop"></div>
            <div class="popHeader">Описание Задачи</div>
            <div class="headerSeparator"></div>
            <div class="description"></div>
            <div class="taskStatus">Статус задачи: </div>
            <div class="status"></div>
            <button class="changeStatus">Изменить статус</button>
            <div id="taskIdField" style="display: none;"></div>
        </div>
    </form>
</body>
</html>
